﻿using System;
using System.Collections.Generic;
using System.Linq;
using DLM.Domain.Model;
using DLM.Domain.Repositories;
using DLM.Infrastructure.UnitOfWork;
using DLM.Infrastructure.Domain;


namespace DLM.Data.EF.CodeFirst.Repositories
{
    public class PhotoRepository : Repository<Photo, int>, IPhotoRepository
    {
        public PhotoRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        { }

        public new System.Collections.IEnumerator GetEnumerator()
        {
            throw new NotImplementedException();
        }

        public IEnumerable<Photo> FindByUser(int userID)
        {
            if (userID < 0)
            {
                throw new ArgumentNullException("Id cannot be negative!");
            }
            return this.ActiveContext.Photo.Where(p => p.UserID == userID).ToList();
        }


        public int PhotoCount(int userID)
        {
            if (userID < 0)
            {
                throw new ArgumentNullException("Id cannot be negative!");
            }
            return this.ActiveContext.Photo.Count(p => p.UserID == userID);
        }
    }
}
